
#include "semantics_property.h"
#include "main_container.h"
#include "semantic_analyzer.h"
extern MainContainer * CompilerData;

SemanticsProperty::SemanticsProperty()
{
	this->CurrentContext = -1;

	this->ModifierAbstract = false;
	this->ModifierFinal = false;
	this->ModifierOverride = false;
	this->ModifierPrivate = false;
	this->ModifierProtected = false;
	this->ModifierPublic = false;
	this->ModifierStatic = false;
	this->ModifierVirtual = false;

	this->MethodRead = new SemanticsMethod();
	this->MethodWrite = new SemanticsMethod();

	this->DataType = new SemanticsDataType();

	this->Name = new GenericTable<int>();

}


SemanticsProperty::~SemanticsProperty()
{
	if(MethodRead != NULL)
	{
		delete MethodRead;
		MethodRead = NULL;
	}

	if(MethodWrite != NULL)
	{
		delete MethodWrite;
		MethodWrite = NULL;
	}

	if(DataType != NULL)
	{
		delete DataType;
		DataType = NULL;
	}

	if(Name != NULL)
	{
		delete Name;
		Name = NULL;
	}
}


#ifdef DEBUG
void SemanticsProperty::DebugXMLOutput(FILE * fo)
{
	fprintf(fo, "<semanticsProperty name=\"");
	SemanticAnalyzer::DebugOutputNameFromTable(fo, this->Name, CompilerData->Units);

	fprintf(fo, "\" currentContext=\"");
	fprintf(fo, "%d", this->CurrentContext);

	fprintf(fo, "\" modifierPrivate=\"");
	if (this->ModifierPrivate)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

	fprintf(fo, "\" modifierPublic=\"");
	if (this->ModifierPublic)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

		fprintf(fo, "\" modifierProtected=\"");
	if (this->ModifierProtected)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

			fprintf(fo, "\" modifierStatic=\"");
	if (this->ModifierStatic)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

	
		fprintf(fo, "\" modifierAbstract=\"");
	if (this->ModifierAbstract)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

			fprintf(fo, "\" modifierFinal=\"");
	if (this->ModifierFinal)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

			fprintf(fo, "\" modifierVirtual=\"");
	if (this->ModifierVirtual)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");

		fprintf(fo, "\" modifierOverride=\"");
	if (this->ModifierOverride)
		fprintf(fo, "true");
	else
		fprintf(fo, "false");
	
	fprintf(fo, "\">\n");


	this->DataType->DebugXMLOutput(fo);
	this->MethodRead->DebugXMLOutput(fo);
	this->MethodWrite->DebugXMLOutput(fo);

	fprintf(fo, "</semanticsProperty>\n");
}
#endif
